//
//  PlayerViewController.m
//  AssistantDriving
//
//  Created by dcr on 2017/8/28.
//  Copyright © 2017年 邓兆太. All rights reserved.
//

#import "PlayerViewController.h"

@interface PlayerViewController ()

@end

@implementation PlayerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _player = [[MPMoviePlayerController alloc] initWithContentURL:_url];
    _player.shouldAutoplay = true;
    _player.view.frame = self.view.bounds;
    _player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:_player.view];
    [_player play];
    
    [self addNotification];
}

- (void)addNotification{
    //监听播放状态
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(videoStateChange) name:MPMoviePlayerPlaybackStateDidChangeNotification object:_player];
    
    //监听退出全屏
    [center addObserver:self selector:@selector(exitFullScreen) name:MPMoviePlayerDidExitFullscreenNotification object:_player];

    //播放完成
    [center addObserver:self selector:@selector(finished) name:MPMoviePlayerPlaybackDidFinishNotification object:_player];
    
    //截图完成
    [center addObserver:self selector:@selector(captureFinished:) name:MPMoviePlayerThumbnailImageRequestDidFinishNotification object:_player];
}


- (void)videoStateChange{
    switch (_player.playbackState) {
        case MPMoviePlaybackStatePlaying:
            DLog(@"MPMoviePlaybackStatePlaying");
            break;
        case MPMoviePlaybackStatePaused:
            DLog(@"MPMoviePlaybackStatePaused");
            break;
        case MPMoviePlaybackStateStopped:
            DLog(@"MPMoviePlaybackStateStopped");
            break;
        case MPMoviePlaybackStateInterrupted:
            DLog(@"MPMoviePlaybackStateStopped");
            break;
        case MPMoviePlaybackStateSeekingForward:
            DLog(@"MPMoviePlaybackStateStopped");
            break;
        case MPMoviePlaybackStateSeekingBackward:
            DLog(@"MPMoviePlaybackStateStopped");
            break;
    }
}

- (void)exitFullScreen{
    DLog(@"...exitFullScreen");
}

- (void)finished{
    DLog(@"...finished");
}

- (void)captureFinished:(NSNotification *)notification{
    DLog(@"...captureFinished");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
